package getsubs.popnapisi;

import java.util.regex.*;

public class SubsInfoMatcher {

    private final Matcher matcher;

    public SubsInfoMatcher(Matcher matcher) {
        this.matcher = matcher;
    }

    public boolean matches() {
        return matcher.matches();
    }

    public String getSeason() {
        return matcher.group(1);
    }

    public String getEpisode() {
        return matcher.group(2);
    }

    public String getRelativeLink() {
        return matcher.group(3);
    }

    public static SubsInfoMatcher createFor(CharSequence input) {
        return new SubsInfoMatcher(seasonEpisodePattern().matcher(input));
    }

    public boolean find() {
        return matcher.find();
    }

    private static Pattern seasonEpisodePattern() {
        return Pattern.compile(
                "Season:\\W*<b>([0-9]+)</b>\\W*"
                + "Episode\\:\\W*<b>([0-9]+)</b>"
                + ",&nbsp;<a href=\"([^\"]*)\">download subtitle</a>");
    }
}
